import { AnalysisResult } from '@/types/sun'

export async function loadSunData(
  id: string,
  force: boolean = false,
  fast: boolean = false
): Promise<AnalysisResult | undefined> {
  force = force ?? false
  fast = fast ?? false
  try {
    // url add ?force=true&fast=true
    const params = new URLSearchParams()
    if (force) params.append('force', 'true')
    params.append('fast', fast ? 'true' : 'false')
    const query = params.toString() ? `?${params.toString()}` : ''
    const response = await fetch(`/api/g/sun/${id}${query}`)
    const data = await response.json()
    return data
  } catch (error) {
    console.error('Error loading file:', error)
    return undefined
  }
}
